﻿using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;

namespace Water_and_electricity_metering_management_system.Models.Entitys;

public partial class WemmsDbContext : DbContext
{
    public WemmsDbContext()
    {
    }

    public WemmsDbContext(DbContextOptions<WemmsDbContext> options)
        : base(options)
    {
    }

    public virtual DbSet<Buiding> Buidings { get; set; }

    public virtual DbSet<ElectricityUseLog> ElectricityUseLogs { get; set; }

    public virtual DbSet<Operator> Operators { get; set; }

    public virtual DbSet<RechargeApply> RechargeApplies { get; set; }

    public virtual DbSet<WaterUseLog> WaterUseLogs { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
        => optionsBuilder.UseSqlServer("Data Source=.;Initial Catalog=WEMMS;Persist Security Info=True;User ID=sa;Password=qwe123580.00;TrustServerCertificate=true");

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Buiding>(entity =>
        {
            entity.ToTable("Buiding");

            entity.Property(e => e.Id)
                .ValueGeneratedNever()
                .HasColumnName("ID");
            entity.Property(e => e.BuidingName)
                .HasMaxLength(10)
                .IsFixedLength();
            entity.Property(e => e.ElectricityBalance).HasColumnType("money");
            entity.Property(e => e.WaterBalance).HasColumnType("money");
        });

        modelBuilder.Entity<ElectricityUseLog>(entity =>
        {
            entity.ToTable("ElectricityUseLog");

            entity.HasIndex(e => e.Id, "IX_ElectricityUseLog");

            entity.Property(e => e.Id)
                .ValueGeneratedNever()
                .HasColumnName("ID");
            entity.Property(e => e.BuidingId).HasColumnName("BuidingID");
            entity.Property(e => e.DailyElectricityConsumption).HasColumnType("money");
            entity.Property(e => e.LogTime).HasColumnType("datetime");
            entity.Property(e => e.RemainingAmount).HasColumnType("money");
            entity.Property(e => e.RemainingElectricityVolume).HasColumnType("money");
            entity.Property(e => e.UnitPriceOfElectricity).HasColumnType("money");
        });

        modelBuilder.Entity<Operator>(entity =>
        {
            entity.ToTable("Operator");

            entity.Property(e => e.Id)
                .ValueGeneratedNever()
                .HasColumnName("ID");
            entity.Property(e => e.PassWord)
                .HasMaxLength(50)
                .IsUnicode(false)
                .IsFixedLength();
        });

        modelBuilder.Entity<RechargeApply>(entity =>
        {
            entity.ToTable("RechargeApply");

            entity.Property(e => e.Id)
                .ValueGeneratedNever()
                .HasColumnName("ID");
            entity.Property(e => e.BuidingId).HasColumnName("BuidingID");
            entity.Property(e => e.Class).HasColumnName("class");
            entity.Property(e => e.DateTime).HasColumnType("datetime");
        });

        modelBuilder.Entity<WaterUseLog>(entity =>
        {
            entity.ToTable("WaterUseLog");

            entity.Property(e => e.Id)
                .ValueGeneratedNever()
                .HasColumnName("ID");
            entity.Property(e => e.BuidingId).HasColumnName("BuidingID");
            entity.Property(e => e.DailyWaterConsumption).HasColumnType("money");
            entity.Property(e => e.LogTime).HasColumnType("datetime");
            entity.Property(e => e.RemainingAmount).HasColumnType("money");
            entity.Property(e => e.RemainingWaterVolume).HasColumnType("money");
            entity.Property(e => e.UnitPriceOfWater).HasColumnType("money");
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
